#include "MYhardware.h"


void Delay_us(uint32_t nus)
{
    uint32_t Delay = nus * 480 / 4;
    do
    {
        __NOP();
    }
    while(Delay --);
}

void Beep(uint32_t ms)
{
    HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, GPIO_PIN_SET);
    HAL_Delay(ms);
    HAL_GPIO_WritePin(BEEP_GPIO_Port, BEEP_Pin, GPIO_PIN_RESET);
}

int KeyScan(int click)
{
    int KeyNum = 0;
    if(KeyL() * KeyM() * KeyR() == 0)
    {
        HAL_Delay(5);
        if(KeyL() == 0)	KeyNum = 1;
        if(KeyM() == 0)	KeyNum = 2;
        if(KeyR() == 0)	KeyNum = 3;
        if(click > 0)
        {
            while(KeyL() * KeyM() * KeyR() == 0);
            HAL_Delay(200);
            if(KeyL() * KeyM() * KeyR() == 0)
            {
                HAL_Delay(5);
                if(KeyL() == 0)		KeyNum = 4;
                if(KeyM() == 0)		KeyNum = 5;
                if(KeyR() == 0)		KeyNum = 6;
            }
            while(KeyL() * KeyM() * KeyR() == 0);
        }
    }
    return KeyNum;
}

